package com.lagou.ModelTest3.First.Two;

import com.lagou.ModelTest3.First.Two.Worker;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class WorkerTest {
    public static void main(String[] args) {
        //定义List集合，在List集合中增加三个员工，基本信息如下:
        // "凤姐" 18 20000
        // "欧阳峰" 60 8000
        // "刘德华" 40 30000
        List t1 = new LinkedList();
        t1.add(new Worker("凤姐",18,20000));
        //在"欧阳峰"之前插入一个员工，信息为：姓名："张柏芝"，年龄：35，工资3300
        t1.add(new Worker("张柏芝",35,3300));
        t1.add(new Worker("欧阳锋",60,8000));
        t1.add(new Worker("刘德华",40,30000));
        //删除"刘德华"的信息
        List t2=new LinkedList();
        t2.add(new Worker("刘德华",40,30000));
        t1.removeAll(t2);
        //利用for 循环遍历，打印List 中所有员工的信息
        for(Object obj:t1){
            System.out.println("List中所有员工的信息:"+obj);
        }
        System.out.println("_________________________________________________________________");
        //利用迭代遍历，对List中所有的员工调用work 方法
        List t4=new LinkedList();
        t4.add("凤姐");
        t4.add("欧阳锋");
        t4.add("张柏芝");
        System.out.println("t4="+t4);//[凤姐, 欧阳锋, 张柏芝]
        Iterator iterator=t4.iterator();
        while(iterator.hasNext()){
            Object obj=iterator.next();
            System.out.println("获取到的元素:"+obj);
            Worker p=new Worker(obj);
            p.work();
        }
        System.out.println("_________________________________________________________________");
        //方法，当姓名、年龄、工资全部相等时候才返回true
        List t3=new LinkedList();
        t3.add(new Worker("刘德华",40,30000));
        boolean b1=t1.equals(t2);
        System.out.println("b1="+b1);//false
        System.out.println("_________________________________________________________________");
        boolean b2=t2.equals(t3);
        System.out.println("b2="+b2);//true
    }
}
